# -*- coding: utf-8 -*-

from WSThread import WSThread
import queue, requests

class HostsBruteThread(WSThread):
	def __init__(self, job, result, ip, domain, expr, counter):
		super().__init__(job, result)
		self.ip = ip
		self.domain = domain
		self.expr = expr
		self.counter = counter
	
	def run(self):
		while self.running:
			names = self.job.get_nowait()
			
			reqSess = requests.session()	
			for name in names:
				self.counter.up()
				
				resp = reqSess.get("http://" + self.ip, headers={'Host': name + '.' + self.domain if len(self.domain) else name})
				try:
					resp.text.index(self.expr)
				except ValueError:
					self.result.put(name + '.' + self.domain)
			
			if len(names) < 10:
				self.running = False
				
	
		